/*
 * _DoDictionaryMultimap.h
 *
 *  Created on: Oct 18, 2012
 *      Author: wtao
 */

#ifndef DODICTIONARYMULTIMAP_H_
#define DODICTIONARYMULTIMAP_H_

#include "_DoCompositeObject.h"
#include "DoName.h"
#include <unordered_map>

using namespace std;

class _DoDictionaryMultimap: public _DoCompositeObject
{
public:
	typedef	unordered_multimap< CRefPtr< _DoObject >, CRefPtr< _DoObject >, DoName > CObjMultimap;
	typedef pair<CObjMultimap::iterator, CObjMultimap::iterator> CDictRange;
	typedef pair< CRefPtr< _DoObject >, CRefPtr< _DoObject > > CDictEntry;

protected:
	_DoDictionaryMultimap(const _DoDictionaryMultimap&);
	_DoDictionaryMultimap& operator=(const _DoDictionaryMultimap&);

	CObjMultimap mDict;
public:
	_DoDictionaryMultimap(const std::string &name);
	virtual ~_DoDictionaryMultimap();

	virtual void clear() {
		mDict.clear();
	}

	CDictRange get(CRefPtr<_DoObject > key) {
		return mDict.equal_range(key);
	}

	void put(CRefPtr< _DoObject > key, CRefPtr< _DoObject > value) {
		value->setText(key->getText());
		mDict.insert(CDictEntry(key, value));
	}

	virtual size_t size() const {
		return mDict.size();
	}

	bool containsKey(CRefPtr< _DoObject > key) {
		return mDict.count(key) != 0;
	}
};

#endif /* DODICTIONARYMULTIMAP_H_ */
